package com.tech.zhidengxian.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tech.zhidengxian.model.dataobject.GoodsDO;
import com.tech.zhidengxian.model.dataobject.MessageDO;
import com.tech.zhidengxian.model.dto.request.MessageRequest;

public interface MessageMapper extends BaseMapper<MessageDO> {
    default int insertMessage(MessageDO messageDO){
        return insert(messageDO);
    }

    default IPage<MessageDO> pageQueryMessage(MessageRequest messageRequest){
        Page<MessageDO> page = new Page<>(messageRequest.getCurrentPage(), messageRequest.getPageSize());
        LambdaQueryWrapper<MessageDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MessageDO::getCid,messageRequest.getChatId())
                .orderByAsc(MessageDO::getCreateTime);
        return selectPage(page,wrapper);

    }
}
